<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>记账簿</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    {% load static %}
    <link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
    <script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/home/">记账本</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="{% url 'list' %}">赊账表 <span class="sr-only">(current)</span></a></li>
        <li><a href="{% url 'list1' %}">还清记录</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">更多 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="{% url 'list2' %}">结清表</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
            {% csrf_token %}
          {% if request.user.is_authenticated %}
          <li><a>welcome,{{ request.user.username }}</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">更多操作 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">修改头像</a></li>
            <li><a href="" data-target=".bs-example-modal-lg" data-toggle="modal">修改密码</a></li>
            <li><a href="/backend/">后台管理</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="/logout/" >注销</a></li>
          </ul>
        </li>
              {% else %}
                <li><a href="/login/">登录</a></li>
                <li><a href="/register/">注册</a></li>
          {% endif %}
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-3">
            <div class="list-group">
              <a href="#" class="list-group-item active">
                首页
              </a>
              <a href="{% url 'list' %}" class="list-group-item">赊账列表</a>
              <a href="{% url 'list1' %}" class="list-group-item">还款列表</a>
              <a href="{% url 'list2' %}" class="list-group-item">交易完成列表</a>
              <a href="#" class="list-group-item">其他</a>
            </div>
        </div>
        <div class="col-md-9">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title">记账管理系统 <span class="glyphicon glyphicon-duplicate pull-right"></span></h3>
              </div>
              <div class="panel-body">
                  {% block content %}
                    <div class="jumbotron">
                      <h1>welcome to account book!!!!</h1>
                      <p>...</p>
                      <p><a class="btn btn-primary btn-lg" href="#" role="button">点击就送优惠券</a></p>
                    </div>
                  {% endblock %}
              </div>
            </div>
             {#修改密码模态框代码#}
            <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
              <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                        <div class="row">
                            <div class="col-md-8 col-md-offset-2">
                                <h2 class="text-center">修改密码</h2>
                                <form>
                                    {% csrf_token %}
                                    <div class="form-group">
                                        <label for="id_username">用户名</label>
                                        <input type="text" name="username" value="{{ request.user.username }}" disabled id="id_username" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label for="id_old_password">旧密码</label>
                                        <input type="password" name="old_password" id="id_old_password" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label for="id_new_password">新密码</label>
                                        <input type="password" name="new_password" id="id_new_password" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label for="id_confirm_password">确认密码</label>
                                        <input type="password" name="confirm_password" id="id_confirm_password" class="form-control">
                                    </div>
                                    <input type="button" class="btn btn-primary" id="id_submit" value='确认'>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <span class="errors" style="color: red"></span>
                                    <hr>
                    </form>
                            </div>
                        </div>
                    </div>
              </div>
            </div>
                        {#修改密码模态框代码#}
        </div>
    </div>
</div>
<script>
    $('#id_submit').click(function () {
        $.ajax({
            url:"/set_password/",
            type:'post',
            data:{
                'old_password':$('#id_old_password').val(),
                'new_password':$('#id_new_password').val(),
                'confirm_password':$('#id_confirm_password').val(),
                'csrfmiddlewaretoken':'{{ csrf_token }}',
            },
            success:function (data) {
                if (data.code == 100){
                    location.href = data.url
                }else{
                    $('.errors').text(data.msg)
                }

            }


        })
    })
</script>
</body>
</html>